home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / bbs / pad311.zip / PHONE.MH < prev    next >
Text File  |  1996-08-21  |  3KB  |  99 lines

  1. #ifndef __PHONE_MH
  2. #define __PHONE_MH
  3.  
  4. #ifndef __SETTINGS_MH
  5. #include "settings.mh"
  6. #endif
  7.  
  8. #ifndef __IN_MH
  9. #include "in.mh"
  10. #endif
  11.  
  12. #ifndef __STRIPNUM_MH
  13. #include "stripnum.mh"
  14. #endif
  15.  
  16. // Global variables
  17.  
  18. int validPhone (Ref string: newPhoneNum) {
  19.   int: phoneLen, num_phone_len;
  20.   num_phone_len := countChar (str_phone_format,'#');
  21.   phoneLen := stripNonNumeric (newPhoneNum);
  22.   if (phoneLen = num_phone_len - strlen (str_assume_phone_pfx)) {
  23.     newPhoneNum := str_assume_phone_pfx + newPhoneNum;
  24.     return True;
  25.     };
  26.   return (phoneLen = num_phone_len);
  27.   }
  28.  
  29. int getPhone (string: message, Ref string: phoneNum) {
  30.   int: phoneLen;
  31.   for (;;) {
  32.     print (message + "[" + str_phone_format + "]: ");
  33.     input_str_ani (phoneNum);
  34.     phoneLen := stripNonNumeric (phoneNum);
  35.     if (phoneLen = 0) return False;                           // If no phone number entered, cancel
  36.     if (validPhone (phoneNum)) return True;
  37.     print (str_bad_phone_number);
  38.     };
  39.   return True;
  40.   }
  41.  
  42. void beautifyPhone (string: parsedPhone, Ref string: result) {
  43.   int: formatPos, phonePos, resultPos;
  44.   string: format;
  45.  
  46.   format := str_phone_format;
  47.   result := "";
  48.   if (validPhone (parsedPhone) = 0) return;
  49.   phonePos := 1;
  50.   resultPos := 1;
  51.   for (formatPos := 1; formatPos <= strlen (str_phone_format); formatPos := formatPos + 1) {
  52.     if (format [formatPos] = '#') {
  53.       result [resultPos] := parsedPhone [phonePos];
  54.       phonePos := phonePos + 1;
  55.       resultPos := resultPos + 1;
  56.       }
  57.     else {
  58.       result [resultPos] := format [formatPos];
  59.       resultPos := resultPos + 1;
  60.       };
  61.     };
  62.   }
  63.  
  64. string getNewPhoneNumber (string: oldPhone) {
  65.   string: parsedPhone, prettyPhone, tempPhone;
  66.   char: key;
  67.  
  68.   parsedPhone := oldPhone;
  69.   if (validPhone (parsedPhone) = False) {
  70.     if (getPhone (str_change_phone, parsedPhone) = 0)
  71.       return "";
  72.     };
  73.   do {
  74.     beautifyPhone (parsedPhone,prettyPhone);
  75.     key := input_list_ani ("Ynq\r", str_press_ynq,
  76.         str_check_phone1 + prettyPhone + str_check_phone2);
  77.  
  78.     if (key = '\r') key := 'Y';
  79.     if (key = 'N') {
  80.       if (getPhone (str_change_phone, tempPhone) > 0) parsedPhone := tempPhone;
  81.       };
  82.     if (key = 'Q') return "";
  83.     } while (key <> 'Y');
  84.  
  85.   return prettyPhone;
  86.   }
  87.  
  88. string guessDataPhone () {
  89.   string: parsedPhone;
  90.   parsedPhone := usr.dataphone;
  91.   if (stripNonNumeric (parsedPhone) = 0) {
  92.     parsedPhone := usr.phone;
  93.     stripNonNumeric (parsedPhone);
  94.     };
  95.   return parsedPhone;
  96.   }
  97.  
  98. #endif
  99.